package com.rxkj.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;


/**
 * 页面数据
 *
 * @author alex
 * @date 2022-10-26 15:10:55
 */
@ApiModel("分页查询封装类")
public class PageData<T> {

    @ApiModelProperty(value = "当前页码")
    private int currentPage;

    @ApiModelProperty(value = "每页数据条数")
    private int pageSize;

    @ApiModelProperty(value = "查询出的总条数")
    private Long totalRows;

    @ApiModelProperty(value = "计算出来的总页数")
    private Long totalPages;

    @ApiModelProperty(value = "查询对象")
    private List<T> rows;

    @ApiModelProperty(value = "查询start")
    private int start;

    @ApiModelProperty(value = "查询end")
    private int end;

    public PageData() {
    }

    public PageData(int currentPage, int pageSize, Long totalRows) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalRows = totalRows;
        //计算总页数
        this.totalPages = ((Double)Math.ceil(this.totalRows *1.0/ this.pageSize)).longValue();
        //计算 start
        this.start = (currentPage - 1) * pageSize;
        //计算 end
        this.end = pageSize;
    }

    public PageData(int currentPage, int pageSize, Long totalRows, int totalPages, List<T> rows, int start, int end) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalRows = totalRows;
        this.totalPages = ((Double)Math.ceil(this.totalRows *1.0/ this.pageSize)).longValue();
        this.rows = rows;
        this.start = (currentPage - 1) * pageSize;
        this.end = pageSize;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getEnd() {
        return end;
    }

    public void setEnd(int end) {
        this.end = end;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Long getTotalRows() {
        return totalRows;
    }

    public void setTotalRows(Long totalRows) {
        this.totalRows = totalRows;
    }

    public Long getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(Long totalPages) {
        this.totalPages = totalPages;
    }

    public List<T> getRows() {
        return rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }

    @Override
    public String toString() {
        return "PageData{" +
                "currentPage=" + currentPage +
                ", pageSize=" + pageSize +
                ", totalRows=" + totalRows +
                ", totalPages=" + totalPages +
                ", rows=" + rows +
                ", start=" + start +
                ", end=" + end +
                '}';
    }
}
